package com.shqcjd.generalplatformprojectclient.ui.presenter;

import com.shqcjd.generalplatformprojectclient.api.ApiService;
import com.shqcjd.generalplatformprojectclient.helper.rxjavahelper.RxObserver;
import com.shqcjd.generalplatformprojectclient.helper.rxjavahelper.RxSchedulersHelper;
import com.shqcjd.generalplatformprojectclient.model.ResponseData;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceHistoryBean;
import com.shqcjd.generalplatformprojectclient.ui.base.BasePresenter;
import com.shqcjd.generalplatformprojectclient.ui.view.GuidanceHistoryView;

import java.util.List;

import io.reactivex.disposables.Disposable;

/**
 * 指导历史记录
 * Created by sy on 2018/12/17.
 */

public class GuidanceHistoryPresenter extends BasePresenter<GuidanceHistoryView> {
    /**
     * 刷新数据
     */
    public void getRefreshData(int id){
        ApiService.guideHistoryList(id)
                .compose(RxSchedulersHelper.io_main())
                .subscribe(new RxObserver<ResponseData<List<GuidanceHistoryBean>>>() {
                    @Override
                    public void _onSubscribe(Disposable d) {
                        super._onSubscribe(d);
                        getView().showProgress("加载中..");
                    }

                    @Override
                    public void _onNext(ResponseData<List<GuidanceHistoryBean>> data) {
                        if (data.code == 0) {
                            getView().getRefreshDataSuccess(data.data);
                        } else {
                            getView().getDataError(data.message);
                        }
                        getView().hideProgress();
                    }

                    @Override
                    public void _onError(String errorMessage) {
                        getView().hideProgress();
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        getView().hideProgress();
                    }
                });
    }
}
